﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EasyNetQ;
using Microsoft.AspNetCore.Mvc;
using NETCORE.RabbitMQ.Messages;

namespace NETCORE.RabbitMQ.API.Publisher.Controllers
{
    [Produces("application/json")]
    [Route("api/Client")]
    public class ClientController : Controller
    { 
        private readonly IBus bus;

        public ClientController(  IBus _bus)
        { 
            bus = _bus;
        }
         
        [Route("GetVs")]
        [HttpGet]
        public async Task<string> GetVs()
        {
            // Business Logic here...
            // eg.Add new client to your service databases via EF
            // Sample Publish
            ClientMessage message = new ClientMessage
            {
                ClientId = 12,
                ClientName = "lihongyuan",
                Sex ="sss",
                Age = 29,
                SmokerCode = "N",
                Education = "Master",
                YearIncome = 100000
            };
            await bus.PublishAsync(message);

            return "Add Client Success! You will receive some letter later.";
        }
    }
}
